# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Home of constraint solver constraint_solver

load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_python//python:defs.bzl", "py_library")
load("@rules_python//python:proto.bzl", "py_proto_library")

package(default_visibility = ["//visibility:public"])

config_setting(
    name = "on_linux",
    constraint_values = ["@platforms//os:linux"],
)

config_setting(
    name = "on_macos",
    constraint_values = ["@platforms//os:macos"],
)

config_setting(
    name = "on_windows",
    constraint_values = ["@platforms//os:windows"],
)

proto_library(
    name = "assignment_proto",
    srcs = ["assignment.proto"],
)

cc_proto_library(
    name = "assignment_cc_proto",
    deps = [":assignment_proto"],
)

proto_library(
    name = "search_limit_proto",
    srcs = ["search_limit.proto"],
)

cc_proto_library(
    name = "search_limit_cc_proto",
    deps = [":search_limit_proto"],
)

java_proto_library(
    name = "search_limit_java_proto",
    deps = [":search_limit_proto"],
)

proto_library(
    name = "demon_profiler_proto",
    srcs = ["demon_profiler.proto"],
)

cc_proto_library(
    name = "demon_profiler_cc_proto",
    deps = [":demon_profiler_proto"],
)

proto_library(
    name = "search_stats_proto",
    srcs = ["search_stats.proto"],
)

cc_proto_library(
    name = "search_stats_cc_proto",
    deps = [":search_stats_proto"],
)

java_proto_library(
    name = "search_stats_java_proto",
    deps = [":search_stats_proto"],
)

proto_library(
    name = "solver_parameters_proto",
    srcs = ["solver_parameters.proto"],
)

cc_proto_library(
    name = "solver_parameters_cc_proto",
    deps = [":solver_parameters_proto"],
)

java_proto_library(
    name = "solver_parameters_java_proto",
    deps = [":solver_parameters_proto"],
)

py_proto_library(
    name = "assignment_py_pb2",
    deps = [":assignment_proto"],
)

py_proto_library(
    name = "search_limit_py_pb2",
    deps = [":search_limit_proto"],
)

py_proto_library(
    name = "demon_profiler_py_pb2",
    deps = [":demon_profiler_proto"],
)

py_proto_library(
    name = "search_stats_py_pb2",
    deps = [":search_stats_proto"],
)

py_proto_library(
    name = "solver_parameters_py_pb2",
    deps = [":solver_parameters_proto"],
)

py_library(
    name = "constraint_solver_py_pb2",
    deps = [
        ":assignment_py_pb2",
        ":demon_profiler_py_pb2",
        ":search_limit_py_pb2",
        ":search_stats_py_pb2",
        ":solver_parameters_py_pb2",
    ],
)

# ----- Constraint Programming core engine -----

# This is the main library.
# TODO(user): split this monolithic library into independent components.
# Do the same for others.
cc_library(
    name = "cp",
    srcs = [
        "alldiff_cst.cc",
        "assignment.cc",
        "constraint_solver.cc",
        "constraints.cc",
        "count_cst.cc",
        "default_search.cc",
        "demon_profiler.cc",
        "deviation.cc",
        "diffn.cc",
        "element.cc",
        "expr_array.cc",
        "expr_cst.cc",
        "expressions.cc",
        "graph_constraints.cc",
        "interval.cc",
        "local_search.cc",
        "model_cache.cc",
        "pack.cc",
        "range_cst.cc",
        "resource.cc",
        "sched_constraints.cc",
        "sched_expr.cc",
        "sched_search.cc",
        "search.cc",
        "table.cc",
        "timetabling.cc",
        "trace.cc",
        "utilities.cc",
        "visitor.cc",
    ],
    hdrs = [
        "constraint_solver.h",
        "constraint_solveri.h",
    ],
    deps = [
        ":assignment_cc_proto",
        ":demon_profiler_cc_proto",
        ":search_limit_cc_proto",
        ":search_stats_cc_proto",
        ":solver_parameters_cc_proto",
        ":routing_parameters_cc_proto",
        "//ortools/base",
        "//ortools/base:bitmap",
        "//ortools/base:file",
        "//ortools/base:int_type",
        "//ortools/base:intops",
        "//ortools/base:iterator_adaptors",
        "//ortools/base:map_util",
        "//ortools/base:mathutil",
        "//ortools/base:recordio",
        "//ortools/base:stl_util",
        "//ortools/base:strong_vector",
        "//ortools/base:sysinfo",
        "//ortools/base:timer",
        "//ortools/base:types",
        "//ortools/graph:hamiltonian_path",
        "//ortools/util:bitset",
        "//ortools/util:cached_log",
        "//ortools/util:monoid_operation_tree",
        "//ortools/util:piecewise_linear_function",
        "//ortools/util:range_minimum_query",
        "//ortools/util:saturated_arithmetic",
        "//ortools/util:sorted_interval_list",
        "//ortools/util:string_array",
        "//ortools/util:tuple_set",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/base:log_severity",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/random",
        "@com_google_absl//absl/random:distributions",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
    ],
)

# ----- Routing and ArcRouting -----

proto_library(
    name = "routing_enums_proto",
    srcs = ["routing_enums.proto"],
)

cc_proto_library(
    name = "routing_enums_cc_proto",
    deps = [":routing_enums_proto"],
)

java_proto_library(
    name = "routing_enums_java_proto",
    deps = [":routing_enums_proto"],
)

proto_library(
    name = "routing_ils_proto",
    srcs = ["routing_ils.proto"],
    deps = [":routing_enums_proto"],
)

cc_proto_library(
    name = "routing_ils_cc_proto",
    deps = [":routing_ils_proto"],
)

py_proto_library(
    name = "routing_ils_py_pb2",
    deps = [":routing_ils_proto"],
)

java_proto_library(
    name = "routing_ils_java_proto",
    deps = [":routing_ils_proto"],
)

proto_library(
    name = "routing_parameters_proto",
    srcs = ["routing_parameters.proto"],
    deps = [
        ":routing_enums_proto",
        ":routing_ils_proto",
        ":solver_parameters_proto",
        "//ortools/sat:sat_parameters_proto",
        "//ortools/util:optional_boolean_proto",
        "@com_google_protobuf//:duration_proto",
    ],
)

cc_proto_library(
    name = "routing_parameters_cc_proto",
    deps = [":routing_parameters_proto"],
)

java_proto_library(
    name = "routing_parameters_java_proto",
    deps = [":routing_parameters_proto"],
)

py_proto_library(
    name = "routing_parameters_py_pb2",
    deps = [":routing_parameters_proto"],
)

py_proto_library(
    name = "routing_enums_py_pb2",
    deps = [":routing_enums_proto"],
)

cc_library(
    name = "routing_parameters",
    srcs = ["routing_parameters.cc"],
    hdrs = ["routing_parameters.h"],
    deps = [
        ":cp",
        ":routing_enums_cc_proto",
        ":routing_ils_cc_proto",
        ":routing_parameters_cc_proto",
        ":routing_parameters_utils",
        ":solver_parameters_cc_proto",
        "//ortools/base",
        "//ortools/base:proto_enum_utils",
        "//ortools/base:protoutil",
        "//ortools/base:types",
        "//ortools/port:proto_utils",
        "//ortools/sat:sat_parameters_cc_proto",
        "//ortools/util:optional_boolean_cc_proto",
        "//ortools/util:testing_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "routing_parameters_utils",
    srcs = ["routing_parameters_utils.cc"],
    hdrs = ["routing_parameters_utils.h"],
    deps = [
        ":routing_parameters_cc_proto",
        "//ortools/util:optional_boolean_cc_proto",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "routing_types",
    hdrs = ["routing_types.h"],
    deps = [
        "//ortools/base:int_type",
        "//ortools/util:piecewise_linear_function",
    ],
)

cc_library(
    name = "routing_utils",
    srcs = ["routing_utils.cc"],
    hdrs = ["routing_utils.h"],
    visibility = ["//visibility:public"],
    deps = [
        "//ortools/util:saturated_arithmetic",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "routing_neighborhoods",
    srcs = ["routing_neighborhoods.cc"],
    hdrs = ["routing_neighborhoods.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":cp",
        ":routing_types",
        ":routing_utils",
        "//ortools/base:types",
        "//ortools/util:bitset",
        "//ortools/util:saturated_arithmetic",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "routing_index_manager",
    srcs = ["routing_index_manager.cc"],
    hdrs = ["routing_index_manager.h"],
    deps = [
        ":routing_types",
        "//ortools/base",
        "//ortools/base:strong_vector",
        "//ortools/base:types",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "routing",
    srcs = [
        "routing.cc",
        "routing_breaks.cc",
        "routing_constraints.cc",
        "routing_decision_builders.cc",
        "routing_filters.cc",
        "routing_flow.cc",
        "routing_ils.cc",
        "routing_insertion_lns.cc",
        "routing_lp_scheduling.cc",
        "routing_sat.cc",
        "routing_search.cc",
    ],
    hdrs = [
        "routing.h",
        "routing_constraints.h",
        "routing_decision_builders.h",
        "routing_filter_committables.h",
        "routing_filters.h",
        "routing_ils.h",
        "routing_insertion_lns.h",
        "routing_lp_scheduling.h",
        "routing_search.h",
    ],
    copts = select({
        "on_linux": [],
        "on_macos": [],
        "on_windows": ["/Zc:preprocessor"],
        "//conditions:default": [],
    }),
    deps = [
        ":cp",
        ":routing_enums_cc_proto",
        ":routing_index_manager",
        ":routing_neighborhoods",
        ":routing_parameters",
        ":routing_parameters_cc_proto",
        ":routing_types",
        ":routing_utils",
        ":solver_parameters_cc_proto",
        "//ortools/base",
        "//ortools/base:dump_vars",
        "//ortools/base:int_type",
        "//ortools/base:map_util",
        "//ortools/base:mathutil",
        "//ortools/base:protoutil",
        "//ortools/base:stl_util",
        "//ortools/base:strong_vector",
        "//ortools/base:types",
        "//ortools/glop:lp_solver",
        "//ortools/glop:parameters_cc_proto",
        "//ortools/graph",
        "//ortools/graph:christofides",
        "//ortools/graph:connected_components",
        "//ortools/graph:ebert_graph",
        "//ortools/graph:linear_assignment",
        "//ortools/graph:min_cost_flow",
        "//ortools/lp_data",
        "//ortools/lp_data:base",
        "//ortools/port:proto_utils",
        "//ortools/sat:cp_model_cc_proto",
        "//ortools/sat:cp_model_solver",
        "//ortools/sat:integer",
        "//ortools/sat:lp_utils",
        "//ortools/sat:model",
        "//ortools/sat:sat_parameters_cc_proto",
        "//ortools/sat:theta_tree",
        "//ortools/util:bitset",
        "//ortools/util:flat_matrix",
        "//ortools/util:optional_boolean_cc_proto",
        "//ortools/util:piecewise_linear_function",
        "//ortools/util:range_minimum_query",
        "//ortools/util:range_query_function",
        "//ortools/util:saturated_arithmetic",
        "//ortools/util:sorted_interval_list",
        "//ortools/util:time_limit",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/functional:bind_front",
        "@com_google_absl//absl/hash",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/log:die_if_null",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@com_google_protobuf//:protobuf",
    ],
)

